package com.e3.basdoc.dept.client;

import java.util.ArrayList;
import java.util.List;

import com.e3.basdoc.dept.model.DeptModel;
import com.e3.basdoc.dept.model.DeptQC;
import com.e3.template.tgf.TGFQueryDialog;
import com.e3.web.core.client.GwtAsyncCallback;
import com.e3.web.core.model.SuperQC;
import com.e3.web.widget.client.MyField;
import com.extjs.gxt.ui.client.widget.form.Field;

public class DeptQueryDialog extends TGFQueryDialog<DeptModel> {

	private DeptRPCServiceAsync service = DeptRPCService.Util.getInstance();

	@Override
	protected SuperQC getQueryCondition() {
		MyField<?> field = getMyFormField(DeptModel.CODE);
		String code = (String) field.getFieldValue();
		field = getMyFormField(DeptModel.NAME);
		String name = (String) field.getFieldValue();

		final DeptQC qc = new DeptQC();
		qc.setCode(code);
		qc.setName(name);
		
		return qc;
	}

	@Override
	protected List<Field<?>> getFormFields() {
		String[] names = { DeptModel.CODE, DeptModel.NAME };
		List<Field<?>> fields = new ArrayList<Field<?>>(names.length);

		for (String name : names) {
			Field<?> formField = DeptHelper.INSTANCE.createFormField(name);
			fields.add(formField);
		}

		return fields;
	}

	@Override
	protected void executeQueryService(SuperQC qc,	GwtAsyncCallback<List<DeptModel>> callback) {
		service.getDeptsByCondition((DeptQC)qc, callback);
	}


}
